import {observable,action} from "mobx";
import * as Apis from "../../apis/docTodoApi";
import { ListViewPage } from 'weaver-mobile-page';

class DocTodoStore{
  
  @observable list = new ListViewPage.Store({ route: '/docToDo' });
  @observable tabs = [];
  @observable officalType = "0";
  @observable dropDown = false;
  @observable loading = false;
  @observable userId = "";//userId

  @action.bound
  getList(formParams){
    this.loading = true;
    const params={
      officalType:this.officalType,
      ...formParams,
    }
    Apis.getList(params).then(res => {
      this.list.getData({ dataKey:res.sessionkey},()=>{
        this.loading = false;
      },true);
    });
  }

  @action.bound 
  getTabs(){
    Apis.getTabs().then(data=>{
      if(data.datalist){
        this.tabs = this.changeTabData(data.datalist);
      }
    })
  }

  changeTabData(tabs){
    tabs.map(item=>{
      if(item.officalType != "0"){
        item.title = `${item.title}(${item.count})`;
      }else{
        item.title = `${item.title}`;
      }
    })
    return tabs;
  }

  @action.bound
  changeTab(tab){
    this.officalType = tab.officalType;
    this.getList()
  }

  @action.bound 
  setOfficalType(officalType){
    this.officalType = officalType;
  }

  //获取用户id
  @action.bound
  getUserId(){
    Apis.getUserId().then(data=>{
      if(data.api_status){
        this.userId = data.userId;
      }
    })
  }

}

export default DocTodoStore;
